﻿
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Utils.Common
{
   public class JsonHelper
    {

        /// <summary>
        /// 序列化json
        /// </summary>
        public static string ObjectToJson<T>(T obj)
        {
            return JsonConvert.SerializeObject(obj);

        }

        /// <summary>
        /// 序列化json
        /// </summary>
        public static string ObjectToJson<T>(List<T> objlist)
        {
            return JsonConvert.SerializeObject(objlist);

        }

        /// <summary>
        /// 反序列化
        /// </summary>
        public static T JsonToObject<T>(string jsonString)
        {
            return JsonConvert.DeserializeObject<T>(jsonString);
        }

        /// <summary>
        /// 反序列化
        /// </summary>
        public static List<T> JsonToObjectList<T>(string jsonString)
        {
            return JsonConvert.DeserializeObject<List<T>>(jsonString);
        }

    }
}
